package it.vidoc.mybatis.sqlquery;

import it.vidoc.mybatis.javaclient.ext.StrnomiMapperExt;
import it.vidoc.mybatis.javamodel.Strnomi03;
import it.vidoc.utils.CreaNomeTabStringhe;
import it.vidoc.utils.MyBatisConnectionFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

public class SqlStrNomi {
	private String alberto = null;
	
	public SqlStrNomi() {
//		try {
//			MyBatisConnectionFactory.openSqlSessionFactory();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
	}
	
	public ArrayList<Integer> GetStrNomi(String parola) {
        MyBatisConnectionFactory.openSqlSession();
		SqlSession sqlSession = MyBatisConnectionFactory.getSqlSession();
		StrnomiMapperExt strnomiMapperExt = sqlSession.getMapper(StrnomiMapperExt.class);
		Map<String, String> param = new HashMap<String, String>();
		param.put("tableName", new CreaNomeTabStringhe().CreaNomeTabStringhe("nome", parola.length()));
		param.put("parola", parola);
		List<Strnomi03> listKanagraNomi = strnomiMapperExt.selectKanagra(param);
		ArrayList<Integer> listKanagra = new ArrayList<Integer>();
		for (int i = 0; i < listKanagraNomi.size(); i++) {
			listKanagra.add(listKanagraNomi.get(i).getKanagra());
		}
		MyBatisConnectionFactory.closeSqlSession();
		return listKanagra;
	}
}
	
